package com.lushuan.ch03_configuration_injection.beans;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @ConfigurationProperties(prefix = "user") 常用与bean 属性和yml 文件的绑定
 */
@Component
@ConfigurationProperties(prefix = "user")  // 支持批量绑定
@Validated
@PropertySource("classpath:data/user.properties")
public class User {
    //@Value("${user.username}")  使用 @ConfigurationProperties(prefix = "user") 之后就不需要单独注入了
    private String username;
    private Integer age;
    private Date birthday;
    private List<String> hobbies;
    private Map<Integer, String> girlFriends;
    private Address address;
    // pojo 中boolean 类型的字段不要以is开头，在fastjson 解析中会丢弃前缀is
    private boolean isDeleted;



    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    public List<String> getHobbies() {
        return hobbies;
    }

    public void setHobbies(List<String> hobbies) {
        this.hobbies = hobbies;
    }

    public Map<Integer, String> getGirlFriends() {
        return girlFriends;
    }

    public void setGirlFriends(Map<Integer, String> girlFriends) {
        this.girlFriends = girlFriends;
    }

    public Address getAddress() {
        return address;
    }

    public void setAddress(Address address) {
        this.address = address;
    }

    @Override
    public String toString() {
        return "User{" +
                "username='" + username + '\'' +
                ", age=" + age +
                ", birthday=" + birthday +
                ", hobbies=" + hobbies +
                ", girlFriends=" + girlFriends +
                ", address=" + address +
                '}';
    }
}
